<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="commontaglib"%>
<%
String path = request.getContextPath();

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
 
<html>
  <head>
    <link rel="stylesheet" href="<%=path%>/css/innerstyle.css" type="text/css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/cupertino/jquery-ui.custom.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="<%=path%>/css/ui.multiselect.css" />
    <script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/jquery-ui.custom.min.js"></script>  
    <script type="text/javascript" src="<%=path%>/js/i18n/grid.locale-cn.js"></script> 
    <script type="text/javascript" src="<%=path%>/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
    <style>
html, body {
	margin: 0;			 
	padding: 0;
	 
    font-size: 85%;
}
</style>
    
  </head>
  
  <script type="text/javascript">  
    var temp_tab_id = "";  

    $(function(){ 
    $("#xinz").button(); 
    $("#chax").button();
    $("#shanc").button();
    $("#tib").button();
    $("#daoc").button();
    $("#fuz").button(); 
    $("#reset").button();
    loadTab();
    $( "#datepicker" ).datepicker($.datepicker.regional[ "zh-CN" ]);
    $( "#datepicker1" ).datepicker($.datepicker.regional[ "zh-CN" ]);  
    $("#myTab").jqGrid('hideCol',["chumdwmc"]); 
    
 });
 
 function loadChildTab(subgrid_id,row_id){
 //alert(subgrid_id);
 //alert(row_id);
 var subgrid_table_id, pager_id;
		subgrid_table_id = subgrid_id+"_t";
		//alert(temp_tab_id);
		if(temp_tab_id!=subgrid_id){
		   $("#"+temp_tab_id).hide();
		}		
		temp_tab_id = subgrid_id;		
		//alert(subgrid_table_id);
		pager_id = "p_"+subgrid_table_id;
		$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
		jQuery("#"+subgrid_table_id).jqGrid({
			url:'<%=path%>/gpjy/findYdxxByBdh.action?bdbh='+row_id,
			datatype: 'json',
    mtype: 'post',         
   	colNames:['操作','出卖人','发货单位名称','煤种','品种','应单数量','应单日期'],
   	colModel:[ 
   	    {name:'Verify',index:'id',width:60,align:"center",sortable:false},
   		{name:'maisdwmc',index:'maisdwmc', width:120 },
   		{name:'shouhdwmc',index:'shouhdwmc', width:120 },
   		{name:'meiz',index:'meiz', width:80 },	
   		{name:'pinz',index:'pinz', width:80 },
   		{name:'shul',index:'shul', width:60 },
   		{name:'qianysj',index:'qianysj', width:80}	
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'baodbh'
         },    	
   	rowNum:5,
   	rowList:[5,10,15],     	
   	pager: '#pager13',   	
   	rownumbers: true,   	 
    viewrecords: true,
    multiselect: true,
    sortorder: 'desc',  
    altRows:true,  
	//caption: "合同列表",
    ondblClickRow: function(){
	    var id = $("#"+subgrid_table_id).jqGrid('getGridParam', 'selrow');
        //alert(id);
        openwindow('<%=path %>/htgl/htcxInfo.action?htbh='+id); 
	},
	gridComplete:function()
	{ //在此事件中循环为每一行添加修改和删除链接 
		var ids=jQuery("#"+subgrid_table_id).jqGrid('getDataIDs'); 
		for(var j=0; j<ids.length; j++)
		{ 
			var id=ids[j]; 
			verify ="<a href='#' style='color:#f60' onclick='Verify("+ id +")'>编辑</a>"; //这里的onclick就是调用了上面的javascript函数 Modify(id) 
			
			jQuery("#"+subgrid_table_id).jqGrid('setRowData',ids[j], { Verify: verify }); 
		} 
	} 
		});
		jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false})
 
 }
 
 function loadTab(){  
    $("#myTab").jqGrid({      
    url:'bdJqgrid.action?index=1',   
    datatype: 'json',
    mtype: 'post',         
   	colNames:['报单号','收货单位名称','煤种','品种','价格','报单数量','应单数量','剩余数量','报单日期'],
   	colModel:[   	      		
   		{name:'baodbh',index:'baodbh', width:120},
   		{name:'sfahdwname',index:'sfahdwname', width:200},
   		{name:'meizname',index:'meizname', width:80 },	
   		{name:'pinzname',index:'pinzname', width:80 },	
   		{name:'danj',index:'danj', width:60 },
   		{name:'shul',index:'shul', width:60 },
   		{name:'yingdsl',index:'yingdsl', width:60 },
   		{name:'shengysl',index:'shengysl', width:60 },
   		{name:'baodsj',index:'baodsj', width:80}		
   	],
   
    jsonReader: {
           repeatitems : false, 
           id: 'baodbh'
         },    	
   	rowNum:10,
   	rowList:[10,20,30],     	
   	pager: '#pager13',   	
   	rownumbers: true,   	 
    viewrecords: true,
    //multiselect: true,
    subGrid: true,    
    sortorder: 'desc',  
    altRows:true,  
	caption: "报单列表",
	subGridRowExpanded:	function(subgrid_id, row_id) {
	loadChildTab(subgrid_id,row_id);	
   }
  });
  $("#myTab").jqGrid('setGridHeight','300px');
  }

// 查询
function search(){ 
  //alert("aaa");  
  var formdata = $("#form1").serialize();  
  $("#myTab").jqGrid('setGridParam',{url:'htcxJqgrid.action?'+formdata+'&index=3',mtype:'post',page:1}).trigger("reloadGrid"); 
}

function openwindow(url){
    var sheight = screen.height-70;
    var swidth = screen.width-10;
   var winoption ="dialogHeight:"+sheight+"px;dialogWidth:"+ swidth +"px;status:yes;scroll:yes;resizable:yes;center:yes";
    var result=window.showModalDialog(url,window,winoption);
    //alert(result);
    if(result ==1){
     reloadhtxx();
      }
    return result;  
}

function reloadhtxx(){
   window.location.href="<%=request.getContextPath()%>/htgl/findHtbgJqgrid.action";
}

function addRow(){
	var hetbh = $("#myTab").jqGrid('getGridParam','selrow');
	//alert(hetbh);
	if(hetbh!=null)
    {
    openwindow('<%=path %>/htgl/htbgInfo.action?htbh='+hetbh);    
    }   
	else
	{
	//警告
      $( "#jinggao" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$( this ).dialog( "close" );
				}
			}
		});
	}
}

function removeRow() {
	var s = $("#"+temp_tab_id+"_t").jqGrid('getGridParam','selrow');
	//alert(s);
	var url = "<%=path%>/htgl/removeHtxxInfo.action?htbh="+s;
	$( "#dialog-confirm" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
                    //alert("aaaa");                                    
                   });
                   //$("#myTab").trigger("reloadGrid"); 
                   $( this ).dialog( "close" ); 
                   reloadhtxx();
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
}

function submitRow() {
	var s = $("#"+temp_tab_id+"_t").jqGrid('getGridParam','selarrrow');
	var url = "<%=path%>/htgl/submitHtxxInfo.action?htbh="+s;
	$( "#dialog-confirm1" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
                    //alert(data);    
                   });                  
                   $( this ).dialog( "close" ); 
                   reloadhtxx();
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});

}

function copyRow(){
    var s = $("#"+temp_tab_id+"_t").jqGrid('getGridParam','selarrrow');
	var url = "<%=path%>/htgl/copyHtxxInfo.action?htbh="+s;
	$( "#dialog-confirm2" ).dialog({
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
					$.post(url, function(data) {
                       
                   });                   
                   //$("#myTab").trigger("reloadGrid");
                   $( this ).dialog( "close" ); 
                   reloadhtxx();                    
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
}

function Verify(id) { //单击修改链接的操作 
  
	openwindow('<%=path %>/htgl/htxgInfo.action?htbh='+id.id);
 
}

//重置
function resetSearch(){
	$('#list_search  input[type=text]').val('');
	$('#list_search select').val('-1');
}

function dc_excel(){ 
	form1.action="<%=path%>/htgl/jytj_excel.action?index=0";
	form1.method = "post";
	form1.submit();
	}

</script>  
<body>  
<div id="best1">
<p></p>
<form id="form1" method="post">

<table id="list_search" cellpadding="0" cellspacing="0" border="0"> 
        <tr>
        	<td>  
            	报单编号:  
            </td>
            <td>
            	<input type="text" class="longtextbox" name="bean.AA" /> 
            </td>
            <td>
                煤种:
            </td>
            <td>
            	<div class="select"><div><s:select name="bean.BB" headerKey="-1" headerValue="请选择"  list="mzList" listKey="diccode" listValue="dicname" id="combobox"/></div></div> 
            </td>            
            <td>
               品种 :
            </td>
            <td>
            	<div class="select"><div><s:select name="bean.CC" headerKey="-1" headerValue="请选择"  list="pzList" listKey="diccode" listValue="dicname" /></div></div>
            </td>
        </tr>
        <tr>
        <td>出卖人:</td>
        <td><input type="text" class="longtextbox" name="bean.DD" /></td>
        <td>发货单位:</td>
        <td><input type="text" class="longtextbox" name="bean.EE" /></td>
        <td>出省站/营业站:</td>
        <td><input type="text" class="longtextbox" name="bean.FF" /></td>
        </tr>
        <tr>
        <td>买受人:</td>
        <td><input type="text" class="longtextbox" name="bean.GG" /></td>
        <td>收货单位:</td>
        <td><input type="text" class="longtextbox" name="bean.HH" /></td>
        <td>到达省/市:</td>
        <td><input type="text" class="longtextbox" name="bean.II" /></td>
        </tr>
        <tr>
        <td>价格:</td>
        <td><input type="text" class="textboxs" name="bean.JJ" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" class="textboxs" name="bean.KK" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>数量:</td>
        <td><input type="text" class="textboxs" name="bean.LL" onKeyUp="this.value=this.value.replace(/\D/g,'');" />
          --
          <input type="text" class="textboxs" name="bean.MM" onKeyUp="this.value=this.value.replace(/\D/g,'');" /></td>
        <td>签订日期:</td>
            <td>
            	<input id="datepicker" type="text" class="textboxs" name="bean.NN" /> -- <input id="datepicker1" type="text" class="textboxs" name="bean.OO" />
            </td>
        </tr>
        <tr>
        <td>合同形式:</td>
        <td><div class="select"><div><s:select name="bean.PP" headerKey="-1" headerValue="请选择"  list="htxsList" listKey="diccode" listValue="dicname" /></div></div></td>
        <td>隶属行业:</td>
        <td><div class="select"><div><s:select name="bean.RR" headerKey="-1" headerValue="请选择"  list="hyList" listKey="diccode" listValue="dicname" /></div></div></td>
        <td>&nbsp;</td><td>&nbsp;</td>
        </tr>
		<tr>			
            <td colspan="5" style="float:right">
            <input id="chax" type="button" value="查询" onclick="search();"/>
            <input id="reset" type="button" value="重置" onclick="resetSearch();"/>
            </td>
            <td>&nbsp;</td>
        </tr>
  </table> 
  </form>   
    <table id="list_search" cellpadding="0" cellspacing="0" border="0">
    <tr>
		    <td align="left">
		    <input id="xinz" type="button" value="成交"  onclick= "addRow();"/>&nbsp;&nbsp;
		    <input id="shanc" type="button"  value="删除" onclick="removeRow();" />&nbsp;&nbsp;
		    <input id="tib" type="button" value="提报" onclick="submitRow();"/>&nbsp;&nbsp;
		    <input id="daoc" type="button" value="导出Excel"  onclick="dc_excel();"/>&nbsp;&nbsp;
		    <input id="fuz" type="button" value="复制"  onclick="copyRow();"/>&nbsp;&nbsp;
		    </td>
            
            
        </tr>
    </table>
    <table id="myTab" class="scroll" cellpadding="0" cellspacing="0"></table>  
   <div id="pager13" class="scroll"></div>  
   <div id="message" class="scroll"></div> 
   <div id="dialog-confirm" title="是否确认删除？"></div>
   <div id="dialog-confirm1" title="是否确认提报？"></div>
   <div id="dialog-confirm2" title="是否确认复制？"></div>
   <div id="jinggao" title="警告:请选择一条合同"></div>
</div> 
</body>
</html>
